package com.ITArmy.controller.admin;

import com.ITArmy.beans.Serialize;
import com.ITArmy.common.ServerResponse;
import com.ITArmy.controller.base.BaseController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Api(value = "后台投稿审核接口层次", tags = "后台投稿审核接口层次Controller层")
@Controller
@RequestMapping("/admin/ContributeAudit")
public class AdminContributeAudit extends BaseController {

    @RequestMapping("/findContributeByTitle")
    @ApiOperation(value = "根据标题模糊查询，",
            httpMethod = "POST", response = ServerResponse.class)
    public String findContributeByTitle(String title, Model model) {
        ServerResponse serializeServerResponse = serializeService.findContributeByTitle(title);
        model.addAttribute("ContributeListByTitle", serializeServerResponse);
        return "Contribute";
    }

    @RequestMapping("/findContributeByType")
    @ApiOperation(value = "根据投稿连载类型搜索，", notes = "类型用固定选择",
            httpMethod = "POST", response = ServerResponse.class)
    public String findContributeByType(Integer tid, Model model) {
        ServerResponse serializeServerResponse = serializeService.findContributeByType(tid);
        model.addAttribute("ContributeListByType", serializeServerResponse);
        return "Contribute";
    }

    @RequestMapping("/list")
    @ApiOperation(value = "遍历投稿信息",
            httpMethod = "POST", response = ServerResponse.class)
    public String list(@RequestParam(value = "page", defaultValue = "1") int page, Model model) {
        PageHelper.startPage(page,9);
        List<Serialize> serializes= serializeService.findContributeSerialize();
        PageInfo PageInfo = new PageInfo<>(serializes,9);
        model.addAttribute("SerializeList", PageInfo);
        return "Contribute";
    }

    @RequestMapping("/approved")
    @ResponseBody
    @ApiOperation(value = "审核通过",
            httpMethod = "POST", response = ServerResponse.class)
    public ServerResponse approved(Long id,String email) {
        return serializeService.putaway(id,(long)1,email);
    }

    @RequestMapping("/refused")
    @ResponseBody
    @ApiOperation(value = "审核不通过",
            httpMethod = "POST", response = ServerResponse.class)
    public ServerResponse refused(Long id,String email) {
        return serializeService.putaway(id,(long)0,email);
    }
}
